/**
 * 
 */
package rachauto.persistence.dao.impl;

import java.io.Serializable;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.transaction.annotation.Transactional;

import rachauto.exceptions.RachAutoException;
import rachauto.persistence.dao.pub.CandidatDao;
import rachauto.persistence.jpa.model.Candidat;

/**
 * @author said
 *
 */
@SuppressWarnings("serial")
@Transactional
public class CandidatDaoImpl implements CandidatDao , Serializable{

	  @PersistenceContext
	  private EntityManager em;
	  
	  public void ajouterCandidat(Candidat candidat) throws RachAutoException{
		  
		  try {
			    em.persist(candidat); 
			} catch (Exception e) {
				throw new RachAutoException(RachAutoException.TECHNICAL,
						                   "impossible de persister ce candidat : "+candidat,
						                   e);
			} 
	  }


	@SuppressWarnings("unchecked")
	public List<Candidat> rechercherListAllCandidats() throws RachAutoException {
		
		List<Candidat> list = null;
		try {
			list = em.createQuery("select c from Candidat c").getResultList();
		} catch (Exception e) {
			throw new RachAutoException(RachAutoException.TECHNICAL,"impossible de trouver la liste des candidats",e);
		}
		return list;
		
	}
	



	
}
